package com.martini.satoken01.auth;

import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author martini at 2021/12/17 11:38
 */
@Slf4j
@Component
public class MyAuthComponent01 implements StpInterface {
    @Override
    public List<String> getPermissionList(Object loginId, String s) {
        log.info("调用了获取权限的方法");
        List<String> permissions = new ArrayList<>();
        if (Objects.equals(10001L, StpUtil.getLoginId())) {
            permissions.add("user:create");
            // permissions.add("user:read");
            permissions.add("user:update");
            permissions.add("user:delete");
        }
        return permissions;
    }

    @Override
    public List<String> getRoleList(Object o, String s) {
        log.info("调用了获取角色的方法");
        List<String> roles = new ArrayList<>();
        if (Objects.equals(10001L, StpUtil.getLoginId())) {
            roles.add("user");
            roles.add("admin");
        }
        return roles;
    }
}
